package com.lzxuni.modules.cropinformation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzxuni.common.utils.StringUtils;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.common.entity.Tree;
import com.lzxuni.modules.cropinformation.entity.TblGrowthInformation;
import com.lzxuni.modules.cropinformation.mapper.TblGrowthInformationMapper;
import com.lzxuni.modules.cropinformation.service.TblGrowthInformationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 作物生长信息 服务实现类
 * </p>
 *
 * @author rdf
 * @since 2020-11-24
 */
@Service
public class TblGrowthInformationServiceImpl extends ServiceImpl<TblGrowthInformationMapper, TblGrowthInformation> implements TblGrowthInformationService {

    @Override
    public PageInfo<TblGrowthInformation> queryPageszxx(PageParameter pageParameter, TblGrowthInformation tblGrowthInformation) {
        if (StringUtils.isNotEmpty(pageParameter.getSidx())) {
            PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows()).setOrderBy(
                    pageParameter.getSidx() + " " + pageParameter.getSord());
        } else {
            PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows());
        }
        List<TblGrowthInformation> tblGrowthInformationList = baseMapper.queryList(tblGrowthInformation);
            for(int i=0;i< tblGrowthInformationList.size();i++){
                String pinjieMonth = tblGrowthInformationList.get(i).getLowerMonth() + "-" + tblGrowthInformationList.get(i).getUpperMonth()+ " "+"月";
                String pinjieTemperature = tblGrowthInformationList.get(i).getLowerTemperature() + "-" + tblGrowthInformationList.get(i).getUpperTemperature()+" "+"℃";
                tblGrowthInformationList.get(i).setPinjieMonth(pinjieMonth);
                tblGrowthInformationList.get(i).setPinjieTemperature(pinjieTemperature);
            }
        PageInfo<TblGrowthInformation> pageInfo = new PageInfo<>(tblGrowthInformationList);
        return pageInfo;
    }


    @Override
    public  List<Tree> getTree(String cropModel){
        List<Tree> modellist = baseMapper.getTree(cropModel);
        return modellist;
    }
}
